import Vue from "vue";
import KFormDesign from "@/pages/system/zerocode/worksheet/components/packages/index.js";
Vue.use(KFormDesign);
import { nodeSchema } from "@/pages/system/zerocode/worksheet/components/packages/utils/index";
// 引入自定义组件
import organization from "@/pages/system/zerocode/worksheet/components/control/organization";
import icon from "@/pages/system/zerocode/worksheet/components/control/icon";
import user from "@/pages/system/zerocode/worksheet/components/control/user";
import sign from "@/pages/system/zerocode/worksheet/components/control/sign";
import serialNo from "@/pages/system/zerocode/worksheet/components/control/serialNo";
import district from "@/pages/system/zerocode/worksheet/components/control/district";
import otherField from "@/pages/system/zerocode/worksheet/components/control/otherField";
import correlation from "@/pages/system/zerocode/worksheet/components/control/correlation/index";
import subtable from "@/pages/system/zerocode/worksheet/components/control/subtable";
import autoComplete from "@/pages/system/zerocode/worksheet/components/control/autoComplete";
import barCode from "@/pages/system/zerocode/worksheet/components/control/barCode";
import dictionary from "@/pages/system/zerocode/worksheet/components/control/dictionary";
import map from "@/pages/system/zerocode/worksheet/components/control/map";

import textCombination from "@/pages/system/zerocode/worksheet/components/control/textCombination";
import total from "@/pages/system/zerocode/worksheet/components/control/total";
import formulaNumber from "@/pages/system/zerocode/worksheet/components/control/formulaNumber";
import formulaFunc from "@/pages/system/zerocode/worksheet/components/control/formulaFunc";
import formulaTime from "@/pages/system/zerocode/worksheet/components/control/formulaTime";

import searchRecord from "@/pages/system/zerocode/worksheet/components/control/searchRecord";

nodeSchema.addSchemas([
  {
    type: "organization", // 组件类型
    label: "组织架构", // 组件名称s
    cicon: "cluster",
    component: organization, // 组件
    options: {
      labelSize: 14,
      labelStyle: "",
      labelColor: "#000000",
      labelFamily: "",
      span: 24,
      size: "default",
      hiddenAdd: false,
      defaultValue: null,
      defaultValueConfig: {
        type: "field", //默认值类型
        field: [], // 默认值:其他字段值
        worksheet: {
          zeroCodeId: undefined, //工作表
          filters: {
            groupOp: "AND",
            rules: [],
            groups: [],
          }, //查询条件
          multipleType: 1, //获取到多条处理1获取第一条，2不获取
          sort: [
            {
              key: undefined,
              type: "",
              sord: "desc",
            },
          ], //排序
          setKey: null, //赋值key
        }, // 默认值:查询工作表
      },
      multiple: false, // 多选
      disabled: false, //是否禁用
      hidden: false, // 是否隐藏，false显示，true隐藏
      width: "100%", // 宽度
      clearable: true, // 可清除
      topOrg: true, //顶级部门
      checkStrictly: true, //父子节点选中状态不再关联
      chosen: [],
      placeholder: "请选择", // 占位内容
      showLabel: true,
    },
    model: "", // 数据字段
    key: "",
    rules: [
      // 校验规则
      {
        required: false,
        message: "必填项",
      },
    ],
  },
  {
    type: "user", // 组件类型
    label: "人员选择", // 组件名称
    component: user, // 组件
    cicon: "user",
    options: {
      labelSize: 14,
      labelStyle: "",
      labelColor: "#000000",
      labelFamily: "",
      span: 24,
      size: "default",
      hiddenAdd: false,
      defaultValue: null,
      defaultValueConfig: {
        type: "field", //默认值类型
        field: [], // 默认值:其他字段值
        worksheet: {
          zeroCodeId: undefined, //工作表
          filters: {
            groupOp: "AND",
            rules: [],
            groups: [],
          }, //查询条件
          multipleType: 1, //获取到多条处理1获取第一条，2不获取
          sort: [
            {
              key: undefined,
              type: "",
              sord: "desc",
            },
          ], //排序
          setKey: null, //赋值key
        }, // 默认值:查询工作表
      },
      multiple: false, // 多选
      disabled: false, //是否禁用
      hidden: false, // 是否隐藏，false显示，true隐藏
      width: "100%", // 宽度
      clearable: true, // 可清除
      chosen: [],
      topOrg: true, //顶级部门
      specificOrg: "", //指定组织范围字段
      placeholder: "请选择", // 占位内容
      showLabel: true,
    },
    model: "", // 数据字段
    key: "",
    rules: [
      // 校验规则
      {
        required: false,
        message: "必填项",
      },
    ],
  },

  {
    type: "searchRecord", // 组件类型
    label: "查询记录", // 组件名称s
    cicon: "search",
    component: searchRecord, // 组件
    options: {
      labelSize: 14,
      labelStyle: "",
      labelColor: "#000000",
      labelFamily: "",
      span: 24,
      hiddenAdd: false,
      defaultValue: "",
      hidden: false, // 是否隐藏，false显示，true隐藏
      showLabel: true,
    },
    model: "", // 数据字段
    key: "",
    rules: [],
  },
  {
    type: "correlation",
    label: "关联记录",
    component: correlation,
    cicon: "block",
    options: {
      labelSize: 14,
      labelStyle: "",
      labelColor: "#000000",
      labelFamily: "",
      span: 24,
      hiddenAdd: false,
      disabled: false, //是否禁用
      hidden: false, // 是否隐藏，false显示，true隐藏
      clearable: true, // 可清除
      placeholder: "请选择", // 占位内容
      showLabel: true,
      showType: "select", //显示方式
      stripe: true, //隔行变色
      records: {
        chosen: false, //是否能够选择
        type: "1", //选择类型1，全部，2有权限数据
        filters: {
          groupOp: "AND",
          rules: [],
          groups: [],
        }, //查询条件
      }, //允许选择已有记录

      zeroCodeId: undefined, //工作表
      type: "single", //single单条，multiple多条
      title: "",
      columns: [], //显示列
      sort: [
        {
          key: "CreateTime",
          sord: "desc",
        },
      ], //排序

      defaultValue: null,
      defaultValueConfig: {
        type: "value", //默认值类型
        field: [], // 默认值:其他字段值
        worksheet: {
          zeroCodeId: undefined, //工作表
          filters: {
            groupOp: "AND",
            rules: [],
            groups: [],
          }, //查询条件
          multipleType: 1, //获取到多条处理1获取第一条，2不获取
          dynamicValueEmpty: 1, //当条件使用的动态值为空时，如何处理？
          sort: [
            {
              key: undefined,
              type: "",
              sord: "desc",
            },
          ], //排序
          setKey: null, //赋值key
          number: 500, //查询数量
        }, // 默认值:查询工作表
      },
      twoway: {
        is: false, //是否是双向关联
        key: undefined, //双向关联字段
      },
      canAdd: true,
      canEdit: true,
      canDelete: true,
      canDetail: true,
      canReport: true,
    },
    model: "", // 数据字段
    key: "",
    rules: [
      {
        required: false,
        message: "必填项",
      },
    ],
  },

  {
    type: "subtable",
    label: "子表",
    component: subtable,
    cicon: "table",
    options: {
      labelSize: 14,
      labelStyle: "",
      labelColor: "#000000",
      labelFamily: "",
      span: 24,
      hiddenAdd: false,
      disabled: false, //是否禁用
      hidden: false, // 是否隐藏，false显示，true隐藏
      clearable: true, // 可清除
      placeholder: "请选择", // 占位内容
      showLabel: true,
      showType: "select", //显示方式
      stripe: true, //隔行变色
      records: {
        chosen: false, //是否能够选择
        type: "1", //选择类型1，全部，2有权限数据
        filters: {
          groupOp: "AND",
          rules: [],
          groups: [],
        }, //查询条件
      }, //允许选择已有记录

      zeroCodeId: undefined, //工作表
      title: "",
      columns: [], //显示列
      sort: [
        {
          key: "CreateTime",
          sord: "desc",
        },
      ], //排序

      defaultValue: null,
      defaultValueConfig: {
        type: "field", //默认值类型
        field: [], // 默认值:其他字段值
        worksheet: {
          zeroCodeId: undefined, //工作表
          filters: {
            groupOp: "AND",
            rules: [],
            groups: [],
          }, //查询条件
          multipleType: 1, //获取到多条处理1获取第一条，2不获取
          sort: [
            {
              key: undefined,
              type: "",
              sord: "desc",
            },
          ], //排序
          setKey: null, //赋值key
        }, // 默认值:查询工作表
      },
      twoway: {
        is: false, //是否是双向关联
        key: undefined, //双向关联字段
      },
      canAdd: true,
      canEdit: true,
      canDelete: true,
      canDetail: true,
      canReport: true,
    },
    model: "", // 数据字段
    key: "",
    rules: [
      {
        required: false,
        message: "必填项",
      },
    ],
  },

  {
    type: "otherField",
    label: "他表字段",
    component: otherField,
    cicon: "book",
    options: {
      labelSize: 14,
      labelStyle: "",
      labelColor: "#000000",
      labelFamily: "",
      span: 24,
      disabled: false, //是否禁用
      hidden: false, // 是否隐藏，false显示，true隐藏
      hiddenAdd: false,
      showLabel: true,
      key: undefined, //组件
      field: undefined, //显示列
      zeroCodeId: undefined, //工作表
      type: null, //显示列数据类型
    },
    model: "", // 数据字段
    key: "",
    rules: [
      {
        required: false,
        message: "必填项",
      },
    ],
  },

  {
    type: "serialNo", // 组件类型
    label: "自动编号", // 组件名称
    cicon: "ordered-list",
    component: serialNo, // 组件
    options: {
      labelSize: 14,
      labelStyle: "",
      labelColor: "#000000",
      labelFamily: "",
      span: 24,
      hiddenAdd: false,
      hidden: false, // 是否隐藏，false显示，true隐藏
      rule: [
        {
          type: "number",
          length: 4,
          incremental: true, //编号超出位数后继续递增
          beginNumber: 1, //开始值
          repeat: "", //重复
        },
      ], //规则
      loadDisplay: false, //加载页面就显示
      userOccupation: false, //用户占用
    },
    model: "", // 数据字段
    key: "",
    rules: [
      // 校验规则
      {
        required: false,
        message: "必填项",
      },
    ],
  },
  {
    type: "map", // 组件类型
    label: "位置选择", // 组件名称
    cicon: "environment",
    component: map, // 组件
    options: {
      labelSize: 14,
      labelStyle: "",
      labelColor: "#000000",
      labelFamily: "",
      span: 24,
      hidden: false, // 是否隐藏，false显示，true隐藏
      hiddenAdd: false,
      showMap: false,
      showLatLng: false,
      customPositon: false,
      clearable: true, // 可清除
      disabled: false, //是否禁用
      placeholder: "请选择", // 占位内容
      dialog: {
        width: "600",
        widthUnit: "px",
        type: "modal",
        centered: false,
        closable: false,
        maskClosable: true,
        zIndex: 1000,
      },
      map: [], //数据映射,选择后会将映射数据值对应显示上
    },
    model: "", // 数据字段
    key: "",
    rules: [
      // 校验规则
      {
        required: false,
        message: "必填项",
      },
    ],
  },
  {
    type: "district",
    label: "省市区",
    component: district,
    cicon: "block",
    options: {
      labelSize: 14,
      labelStyle: "",
      labelColor: "#000000",
      labelFamily: "",
      span: 24,
      size: "default",
      defaultValue: undefined, // 默认值
      defaultValueConfig: {
        type: "value", //默认值类型
        field: [], // 默认值:其他字段值
        worksheet: {
          zeroCodeId: undefined, //工作表
          filters: {
            groupOp: "AND",
            rules: [],
            groups: [],
          }, //查询条件
          multipleType: 1, //获取到多条处理1获取第一条，2不获取
          sort: [
            {
              key: undefined,
              type: "",
              sord: "desc",
            },
          ], //排序
          setKey: null, //赋值key
        }, // 默认值:查询工作表
      },
      options: [],
      //multiple: true, // 多选
      mustEnd: true, //必须最后一级
      disabled: false, //是否禁用
      hidden: false, // 是否隐藏，false显示，true隐藏
      hiddenAdd: false,
      width: "100%", // 宽度
      clearable: true, // 可清除
      placeholder: "请选择", // 占位内容
      showLabel: true,
      levelType: 3, //类型1省，2省市，3省市区，4省市区乡镇
    },
    model: "", // 数据字段
    key: "",
    rules: [
      {
        required: false,
        message: "必填项",
      },
    ],
  },
  {
    type: "dictionary", // 表单类型
    label: "字典", // 标题文字
    cicon: "unordered-list",
    component: dictionary,
    options: {
      labelSize: 14,
      labelStyle: "",
      labelColor: "#000000",
      labelFamily: "",
      size: "default",
      span: 24,
      width: "100%", // 宽度
      defaultValue: undefined, // 下拉选框请使用undefined为默认值
      multiple: false, // 是否允许多选
      disabled: false, // 是否禁用
      clearable: true, // 是否显示清除按钮
      showLabel: true,
      hidden: false, // 是否隐藏，false显示，true隐藏
      hiddenAdd: false,
      placeholder: "请选择", // 默认提示文字
      dictionaryId: undefined, //字典Id
      dictionaryShowType: 1, //字典显示形式,1下拉，2单选，3复选
      dictionaryLevel: 1, //层级,默认下一级
      showSearch: true, // 是否显示搜索框，搜索选择的项的值，而不是文字
    },
    model: "",
    key: "",
    help: "",
    rules: [
      {
        required: false,
        message: "必填项",
      },
    ],
  },
  {
    type: "icon", // 组件类型
    label: "图标选择", // 组件名称
    cicon: "border",
    component: icon, // 组件
    options: {
      labelSize: 14,
      labelStyle: "",
      labelColor: "#000000",
      labelFamily: "",
      span: 24,
      size: "default",
      defaultValue: undefined, // 默认值
      disabled: false, //是否禁用
      hidden: false, // 是否隐藏，false显示，true隐藏
      hiddenAdd: false,
      width: "100%", // 宽度
      clearable: true, // 可清除
      placeholder: "请选择", // 占位内容
    },
    model: "", // 数据字段
    key: "",
    rules: [
      // 校验规则
      {
        required: false,
        message: "必填项",
      },
    ],
  },
  {
    type: "sign",
    label: "手写签名",
    component: sign,
    cicon: "highlight",
    options: {
      labelSize: 14,
      labelStyle: "",
      labelColor: "#000000",
      labelFamily: "",
      span: 24,
      size: "default",
      defaultValue: undefined, // 默认值
      disabled: false, //是否禁用
      hidden: false, // 是否隐藏，false显示，true隐藏
      hiddenAdd: false,
      width: "100%", // 宽度
    },
    model: "", // 数据字段
    key: "",
    rules: [
      {
        required: false,
        message: "必填项",
      },
    ],
  },
  {
    type: "barCode",
    label: "条码",
    component: barCode,
    cicon: "barcode",
    options: {
      labelSize: 14,
      labelStyle: "",
      labelColor: "#000000",
      labelFamily: "",
      span: 24,
      hidden: false, // 是否隐藏，false显示，true隐藏
      hiddenAdd: false,
      width: "100", // 宽度
      defaultValue: undefined,
      showLabel: true,
      type: "barCode", //显示类型：qrcode(二维码)，barcode(条形码)

      qrCode: {
        correctLevel: 1, //容错级别
        size: 100, //尺寸, 长宽一致, 包含外边距
        margin: 10, //二维码图像的外边距, 默认 20px
        colorDark: "#000000", //实点的颜色
        colorLight: "#FFFFFF", //空白区的颜色
        bgSrc: undefined, //欲嵌入的背景图地址
        gifBgSrc: "rgba(0,0,0,0)", //欲嵌入的背景图 gif 地址,设置后普通的背景图将失效。设置此选项会影响性能
        backgroundColor: "#FFFFFF", //背景色
        backgroundDimming: "rgba(255,255,255,1)", //背景色叠加在背景图上的颜色, 在解码有难度的时有一定帮助
        logoSrc: undefined, //嵌入至二维码中心的 LOGO 地址
        logoScale: 0.2, //用于计算 LOGO 大小的值, 过大将导致解码失败, LOGO 尺寸计算公式 logoScale*(size-2*margin), 默认 0.2
        logoMargin: 0, //LOGO 标识周围的空白边框, 默认为0
        logoBackgroundColor: "rgba(255,255,255,1)", //Logo 背景色,需要设置 logo margin
        logoCornerRadius: 0, //LOGO 标识及其边框的圆角半径, 默认为0
        whiteMargin: true, //若设为 true, 背景图外将绘制白色边框
        dotScale: 1, //数据区域点缩小比例,默认为0.35
        autoColor: false, //若为 true, 图像将被二值化处理, 未指定阈值则使用默认值
      },
      barCode: {
        format: "CODE39", //选择要使用的条形码类型
        width: 3, //设置条之间的宽度
        height: 50, //高度
        displayValue: true, //是否在条形码下方显示文字
        text: "456", //覆盖显示的文本
        fontOptions: "bold italic", //使文字加粗体或变斜体
        font: "fantasy", //设置文本的字体
        textAlign: "left", //设置文本的水平对齐方式
        textPosition: "top", //设置文本的垂直位置
        textMargin: 5, //设置条形码和文本之间的间距
        fontSize: 15, //设置文本的大小
        background: "#eee", //设置条形码的背景
        lineColor: "#2196f3", //设置条和文本的颜色。
        margin: 15, //设置条形码周围的空白边距
      },
    },
    model: "", // 数据字段
    key: "",
  },
  {
    type: "autoComplete", // 表单类型
    label: "输入补全", // 标题文字
    component: autoComplete,
    cicon: "font-colors",
    options: {
      labelSize: 14,
      labelStyle: "",
      labelColor: "#000000",
      labelFamily: "",
      size: "default",
      span: 24,
      type: "text",
      width: "100%", // 宽度
      defaultValue: undefined, // 默认值
      defaultValueType: undefined, //类型
      defaultValueBillNo: undefined, //规则编号
      defaultValueApiPath: undefined, //接口地址
      placeholder: "请输入", // 没有输入时，提示文字
      clearable: false,
      addonBefore: "",
      addonAfter: "",
      showLabel: true,
      hidden: false, // 是否隐藏，false显示，true隐藏
      hiddenAdd: false,
      disabled: false, // 是否禁用，false不禁用，true禁用
      only: false, //值唯一
      dynamic: true,
      dynamicConfig: {
        dataSourceId: undefined, //数据源Id
        inParams: [], //输入参数赋值
        title: "",
        key: undefined, //键
        value: undefined, //值
        sidx: undefined, //排序字段
        sord: "desc", //排序方式desc,asc
      },
    },
    model: "",
    key: "",
    help: "",
    rules: [
      {
        required: false,
        message: "必填项",
      },
    ],
  },

  {
    type: "textCombination", // 组件类型
    label: "文本组合", // 组件名称s
    cicon: "diff",
    component: textCombination, // 组件
    options: {
      labelSize: 14,
      labelStyle: "",
      labelColor: "#000000",
      labelFamily: "",
      span: 24,
      hiddenAdd: false,
      defaultValue: "",
      hidden: false, // 是否隐藏，false显示，true隐藏
      showLabel: true,
    },
    model: "", // 数据字段
    key: "",
    rules: [],
  },

  {
    type: "total", // 组件类型
    label: "汇总", // 组件名称s
    cicon: "ordered-list",
    component: total, // 组件
    options: {
      labelSize: 14,
      labelStyle: "",
      labelColor: "#000000",
      labelFamily: "",
      span: 24,
      hiddenAdd: false,
      defaultValue: "",
      hidden: false, // 是否隐藏，false显示，true隐藏
      showLabel: true,
      key: undefined, //关联表
      field: undefined, //汇总字段
      zeroCodeId: undefined, //工作表
      type: 1, //汇总类型
      filters: {
        groupOp: "AND",
        rules: [],
        groups: [],
      }, //查询条件
      precision: 0,
      round: "roundoff", //四舍五入
      addonBefore: "",
      addonAfter: "",
      percentile: false, //千分位
    },
    model: "", // 数据字段
    key: "",
    rules: [],
  },

  {
    type: "formulaNumber", // 组件类型
    label: "公式-数值", // 组件名称s
    cicon: "calculator",
    component: formulaNumber, // 组件
    options: {
      labelSize: 14,
      labelStyle: "",
      labelColor: "#000000",
      labelFamily: "",
      span: 24,
      hiddenAdd: false,
      defaultValue: "",
      code: "",
      convertNullToZero: false,
      precision: 2,
      round: "roundoff",
      omitLastZero: false,
      percentile: false, //千分位
      addonBefore: "",
      addonAfter: "",
      hidden: false, // 是否隐藏，false显示，true隐藏
      showLabel: true,
    },
    model: "", // 数据字段
    key: "",
    rules: [],
  },
  {
    type: "formulaTime", // 组件类型
    label: "公式-日期", // 组件名称s
    cicon: "calculator",
    component: formulaTime, // 组件
    options: {
      labelSize: 14,
      labelStyle: "",
      labelColor: "#000000",
      labelFamily: "",
      span: 24,
      hiddenAdd: false,
      defaultValue: "",

      type: "durationBetweenDates",
      durationBetweenDates: {
        begin: {
          type: "default",
          value: "",
          key: "",
        },
        end: {
          type: "default",
          value: "",
          key: "",
        },
        format: "endzero",
        precision: 2,
        round: "roundoff",
        unit: {
          type: "day",
          show: {
            type: "suffix",
            value: "",
          },
        },
      },
      addSubtractTime: {
        func: "",
        format: "YYYY-MM-DD",
      },

      duration: {
        type: "targetSubtractionNow",
        target: {
          type: "default",
          value: "",
          key: "",
        },
        precision: 2,
        round: "roundoff",
        unit: {
          type: "day",
          show: {
            type: "suffix",
            value: "",
          },
        },
      },

      addonBefore: "",
      addonAfter: "",
      hidden: false, // 是否隐藏，false显示，true隐藏
      showLabel: true,
    },
    model: "", // 数据字段
    key: "",
    rules: [],
  },
  {
    type: "formulaFunc", // 组件类型
    label: "公式-函数", // 组件名称s
    cicon: "calculator",
    component: formulaFunc, // 组件
    options: {
      labelSize: 14,
      labelStyle: "",
      labelColor: "#000000",
      labelFamily: "",
      span: 24,
      hiddenAdd: false,
      defaultValue: "",
      code: "",
      type: "text",
      number: {
        percentile: false, //千分位
        precision: 2,
        round: "roundoff",
        unit: {
          type: "day",
          show: {
            type: "suffix",
            value: "",
          },
        },
      },
      time: {
        format: "YYYY-MM-DD",
      },
      addonBefore: "",
      addonAfter: "",
      hidden: false, // 是否隐藏，false显示，true隐藏
      showLabel: true,
    },
    model: "", // 数据字段
    key: "",
    rules: [],
  },
]);

// 添加分组
nodeSchema.addSchemaGroup({
  title: "业务组件",
  list: [
    "organization",
    "icon",
    "user",
    "sign",
    "district",
    "barCode",
    "serialNo",
    "map",
    "correlation",
    "subtable",
    "otherField",
    "dictionary",
    "autoComplete",
    "textCombination",
    "total",
    "searchRecord",
  ],
});

// 添加分组
nodeSchema.addSchemaGroup({
  title: "公式组件",
  list: ["formulaNumber", "formulaTime", "formulaFunc"],
});
